import { _decorator, Component, director, Label, Node, ProgressBar } from 'cc';
import { _resource, Main } from '../Main';
import { BaseScene } from './BaseScene';
import { Adsdk } from './Adsdk';
const { ccclass, property } = _decorator;

@ccclass('LoadScene')
export class LoadScene extends BaseScene {

    sceneName: string = '加载场景'

    @property(ProgressBar)
    progress: ProgressBar = null!

    /** 是否正在加载 */
    loading: boolean = true

    onLoad() {
        Main.construct()
    }

    init() {
        _resource.fitNode(this.node)
    }
    
    update(dt: number) {
        if (!this.loading) {
            return
        }
        if (_resource) {
            let ratio: number = Math.floor(_resource.loadedResNum / _resource.totalResNum * 100)
            this.progress.progress = ratio / 100
            if (ratio >= 100) {
                this.loading = false
                //请求
                Adsdk.instance.getWxIdFromServer(()=>{
                    director.loadScene('MainScene')
                },()=>{
                    director.loadScene('MainScene')
                })
                
            }
        }
    }
}


